<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var myNum = getRandomIntInclusive(1,50);
        for(var i=0;i<5;i++) {
            var num = prompt("请输入一个1-50之间的数字")
            if (num < myNum) {
                alert('数字小了,您还有'+ (4-i) +'次机会');
            } else if (num > 50 || num < 1) {
                i--;
                alert('请输入一个1-50之间的数字');
                // continue;
            } else if (num > myNum) {
                alert('数字大了，您还有'+ (4-i) +'次机会');
            } else {
                alert('恭喜你，猜对了');
                break
            }
        }

        function getRandomIntInclusive(min, max) {
            min = Math.ceil(min);
            max = Math.floor(max);
            return Math.floor(Math.random() * (max - min + 1)) + min; //含最大值，含最小值 
        }
        console.log(myNum);
    </script>
</head>

<body>

</body>

</html>